package com.qfedu.controller;

import com.qfedu.entity.User;
import com.qfedu.service.UserService;
import com.qfedu.util.Constants;
import com.qfedu.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * projectName: logistics
 * author: CGY
 * time: 2020/10/6 11:05
 * description:登陆模块
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @ResponseBody
    @RequestMapping("/login.do")
    public Result login(String loginId, String password, HttpSession session){
        Result ret = userService.login(loginId,password);
        User user = (User) ret.getData();
        if (user != null){
            session.setAttribute(Constants.LOGIN_USER,user);
        }
        return ret;
    }
    @RequestMapping("/selectFunc.do")
    @ResponseBody
    public Result selectFunc(String loginId,HttpSession session){
        User user = (User) session.getAttribute(Constants.LOGIN_USER);
        if(user == null){
            return Result.error("未登录");
        }
        Result ret = userService.selectFunc(loginId);
        return ret;
    }
}
